﻿///////////////////////////////////////
//////add by yl 2014年8月20日14:01:31
//////主要功能:处理班组设备报修
///////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Catering_DBOpertion;

namespace Catering_Model
{
    /// <summary>
    /// EMASppPlan:班组设备报修单
    /// </summary>
    [Serializable]
    public partial class DMMAccount
    {
        public DMMAccount()
        { }
        #region Model
        private int _id;
        private string _PName;
        private string _PType;
        private string _PManu;
        private string _PCCBH;
        private DateTime _PCCRQ;
        private DateTime _PQYRQ;
        private string _PZCBH;
        private string _PZJNX;
        private string _PYJZ;
        private string _PJSZK;
        private string _PAZDD;
        private string _PUser;
        private string _ClassID;
        private string _GroupID;

        /// <summary>
        /// 
        /// </summary>
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public string PName
        {
            set { _PName = value; }
            get { return _PName; }
        }
        /// <summary>
        /// 作业区编号
        /// </summary>
        public string PType
        {
            set { _PType = value; }
            get { return _PType; }
        }
        /// <summary>
        /// 班组编号
        /// </summary>
        public string PManu
        {
            set { _PManu = value; }
            get { return _PManu; }
        }
        /// <summary>
        /// 设备名称
        /// </summary>
        public string PCCBH
        {
            set { _PCCBH = value; }
            get { return _PCCBH; }
        }

        /// <summary>
        /// 设备型号
        /// </summary>
        public DateTime PCCRQ
        {
            set { _PCCRQ = value; }
            get { return _PCCRQ; }
        }
        /// <summary>
        /// 设备型号
        /// </summary>
        public DateTime PQYRQ
        {
            set { _PQYRQ = value; }
            get { return _PQYRQ; }
        }
        /// <summary>
        /// 日报管理编号
        /// </summary>
        public string PZCBH
        {
            set { _PZCBH = value; }
            get { return _PZCBH; }
        }
        /// <summary>
        /// 作业区编号
        /// </summary>
        public string PZJNX
        {
            set { _PZJNX = value; }
            get { return _PZJNX; }
        }
        /// <summary>
        /// 班组编号
        /// </summary>
        public string PYJZ
        {
            set { _PYJZ = value; }
            get { return _PYJZ; }
        }
        /// <summary>
        /// 设备名称
        /// </summary>
        public string PJSZK
        {
            set { _PJSZK = value; }
            get { return _PJSZK; }
        }

        /// <summary>
        /// 设备型号
        /// </summary>
        public string PAZDD
        {
            set { _PAZDD = value; }
            get { return _PAZDD; }
        }
        /// <summary>
        /// 设备型号
        /// </summary>
        public string PUser
        {
            set { _PUser = value; }
            get { return _PUser; }
        }
        /// <summary>
        /// 设备型号
        /// </summary>
        public string ClassID
        {
            set { _ClassID = value; }
            get { return _ClassID; }
        }
        /// <summary>
        /// 设备型号
        /// </summary>
        public string GroupID
        {
            set { _GroupID = value; }
            get { return _GroupID; }
        }
        #endregion Model
    }
}
namespace Catering_Rules
{
    /// <summary>
    /// Moon
    /// </summary>
    public partial class DMMAccount
    {
        private readonly Catering_Operation.DMMAccount dal = new Catering_Operation.DMMAccount();
        public DMMAccount()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.DMMAccount model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.DMMAccount model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.DMMAccount GetModel(int Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.DMMAccount> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.DMMAccount> DataTableToList(DataTable dt)
        {
            List<Catering_Model.DMMAccount> modelList = new List<Catering_Model.DMMAccount>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Catering_Model.DMMAccount model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
namespace Catering_Operation
{
    /// <summary>
    /// 数据访问类:Moon
    /// </summary>
    public partial class DMMAccount
    {
        public DMMAccount()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Moon");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.DMMAccount model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into DMMAccount(");
            strSql.Append("PName,PType,PManu,PCCBH,PCCRQ,PQYRQ,PZCBH,PZJNX,PYJZ,PJSZK,PAZDD,PUser,ClassID,GroupID)");
            strSql.Append(" values (");
            strSql.Append("@PName,@PType,@PManu,@PCCBH,@PCCRQ,@PQYRQ,@PZCBH,@PZJNX,@PYJZ,@PJSZK,@PAZDD,@PUser,@ClassID,@GroupID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@PName", SqlDbType.VarChar,50),
                    new SqlParameter("@PType", SqlDbType.VarChar,50),
                    new SqlParameter("@PManu", SqlDbType.VarChar,50),
					new SqlParameter("@PCCBH", SqlDbType.VarChar,50),
                    new SqlParameter("@PCCRQ", SqlDbType.Date,-1),
					new SqlParameter("@PQYRQ", SqlDbType.Date,-1),
                    new SqlParameter("@PZCBH", SqlDbType.VarChar,50),
                    new SqlParameter("@PZJNX", SqlDbType.VarChar,50),
					new SqlParameter("@PYJZ", SqlDbType.VarChar,50),
                    new SqlParameter("@PJSZK", SqlDbType.VarChar,50),	
				    new SqlParameter("@PAZDD", SqlDbType.VarChar,50),
                    new SqlParameter("@PUser", SqlDbType.VarChar,50),
					new SqlParameter("@ClassID", SqlDbType.VarChar,50),
                    new SqlParameter("@GroupID", SqlDbType.VarChar,50)};
            parameters[0].Value = model.PName;
            parameters[1].Value = model.PType;
            parameters[2].Value = model.PManu;
            parameters[3].Value = model.PCCBH;
            parameters[4].Value = model.PCCRQ;
            parameters[5].Value = model.PQYRQ;
            parameters[6].Value = model.PZCBH;
            parameters[7].Value = model.PZJNX;
            parameters[8].Value = model.PYJZ;
            parameters[9].Value = model.PJSZK;
            parameters[10].Value = model.PAZDD;
            parameters[11].Value = model.PUser;
            parameters[12].Value = model.ClassID;
            parameters[13].Value = model.GroupID;



            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.DMMAccount model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update DMMAccount set ");
            strSql.Append("PName=@PName,");
            strSql.Append("PType=@PType,");
            strSql.Append("PManu=@PManu,");
            strSql.Append("PCCBH=@PCCBH,");
            strSql.Append("PCCRQ=@PCCRQ,");
            strSql.Append("PQYRQ=@PQYRQ,");
            strSql.Append("PZCBH=@PZCBH,");
            strSql.Append("PZJNX=@PZJNX,");
            strSql.Append("PYJZ=@PYJZ,");
            strSql.Append("PJSZK=@PJSZK,");
            strSql.Append("PAZDD=@PAZDD,");
            strSql.Append("PUser=@PUser");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@PName", SqlDbType.VarChar,50),
                    new SqlParameter("@PType", SqlDbType.VarChar,50),                    
                    new SqlParameter("@PManu", SqlDbType.VarChar,50),
                    new SqlParameter("@PCCBH", SqlDbType.VarChar,-1),
                    new SqlParameter("@PCCRQ", SqlDbType.Date,-1),
                    new SqlParameter("@PQYRQ", SqlDbType.Date,-1),
                    new SqlParameter("@PZCBH", SqlDbType.VarChar,50),                    
                    new SqlParameter("@PZJNX", SqlDbType.VarChar,50),
                    new SqlParameter("@PYJZ", SqlDbType.VarChar,50),
                    new SqlParameter("@PJSZK", SqlDbType.VarChar,50),
                    new SqlParameter("@PAZDD", SqlDbType.VarChar,50),
                    new SqlParameter("@PUser", SqlDbType.VarChar,50),
                    new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = model.PName;
            parameters[1].Value = model.PType;
            parameters[2].Value = model.PManu;
            parameters[3].Value = model.PCCBH;
            parameters[4].Value = model.PCCRQ;
            parameters[5].Value = model.PQYRQ;
            parameters[6].Value = model.PZCBH;
            parameters[7].Value = model.PZJNX;
            parameters[8].Value = model.PYJZ;
            parameters[9].Value = model.PJSZK;
            parameters[10].Value = model.PAZDD;
            parameters[11].Value = model.PUser;
            parameters[12].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from DMMAccount ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Moon ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.DMMAccount GetModel(int Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,PName,PType,PManu,PCCBH,PCCRQ,PQYRQ,PZCBH,PZJNX,PYJZ,PJSZK,PAZDD,PUser from DMMAccount");
            strSql.Append(" where id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,-1)
			};
            parameters[0].Value = Id;

            Catering_Model.DMMAccount model = new Catering_Model.DMMAccount();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.DMMAccount DataRowToModel(DataRow row)
        {
            Catering_Model.DMMAccount model = new Catering_Model.DMMAccount();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.Id = int.Parse(row["id"].ToString());
                }
                if (row["PName"] != null && row["PName"].ToString() != "")
                {
                    model.PName = row["PName"].ToString();
                }
                if (row["PType"] != null && row["PType"].ToString() != "")
                {
                    model.PType = row["PType"].ToString();
                }
                if (row["PManu"] != null && row["PManu"].ToString() != "")
                {
                    model.PManu = row["PManu"].ToString();
                }
                if (row["PCCBH"] != null && row["PCCBH"].ToString() != "")
                {
                    model.PCCBH = row["PCCBH"].ToString();
                }
                if (row["PCCRQ"] != null && row["PCCRQ"].ToString() != "")
                {
                    model.PCCRQ = DateTime.Parse(row["PCCRQ"].ToString());
                }
                if (row["PQYRQ"] != null && row["PQYRQ"].ToString() != "")
                {
                    model.PQYRQ = DateTime.Parse(row["PQYRQ"].ToString());
                }
                if (row["PZCBH"] != null && row["PZCBH"].ToString() != "")
                {
                    model.PZCBH = row["PZCBH"].ToString();
                }
                if (row["PZJNX"] != null && row["PZJNX"].ToString() != "")
                {
                    model.PZJNX = row["PZJNX"].ToString();
                }
                if (row["PYJZ"] != null && row["PYJZ"].ToString() != "")
                {
                    model.PYJZ = row["PYJZ"].ToString();
                }
                if (row["PJSZK"] != null && row["PJSZK"].ToString() != "")
                {
                    model.PJSZK = row["PJSZK"].ToString();
                }
                if (row["PAZDD"] != null && row["PAZDD"].ToString() != "")
                {
                    model.PAZDD = row["PAZDD"].ToString();
                }
                if (row["PUser"] != null && row["PUser"].ToString() != "")
                {
                    model.PUser = row["PUser"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM DMMAccount ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" Id,MoonName,ClassId,Remark ");
            strSql.Append(" FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Id desc");
            }
            strSql.Append(")AS Row, T.*  from Moon T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Moon";
            parameters[1].Value = "Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}